package test.nio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * Created by JOY on 2016/10/3.
 */
public class Client {
    public static void main(String[] args) {
        try {
            // 链接本机8080端口
            Socket socket = new Socket("127.0.0.1", 8080);

            PrintWriter pw = new PrintWriter(socket.getOutputStream());
            pw.println("hello");
            pw.flush();

            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String line = br.readLine();
            System.out.println("server callback: " + line);

            pw.close();
            br.close();
            socket.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
